package com.vite.common.config.knife4j;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.ExternalDocumentation;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.info.License;
import org.springdoc.core.models.GroupedOpenApi;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 文档配置类
 */
@Configuration
public class Knife4jConfig {

	@Bean
	public OpenAPI SpringShopOpenApi() {
		return new OpenAPI()
				.components(new Components())
				.info(new Info().title("yi_vite管理系统接口文档")
				.description("用于接口测试[集成knife4j]")
				.version("v1")
				.license(new License().name("Apache 2.0").url("https://springdoc.org")))
				.externalDocs(new ExternalDocumentation()
				.description("外部文档")
				.url("/doc.html"));
	}

	@Bean
	public GroupedOpenApi SysApi() {
		return BuildGroup("sys系统模块", "com.vite.web.controller.system");
	}

	@Bean
	public GroupedOpenApi CommonApi() {
		return BuildGroup("基础模块", "com.vite.web.controller.common");
	}


	private GroupedOpenApi BuildGroup(String groupName, String... packages) {
		return GroupedOpenApi.builder()
				.group(groupName)
				.packagesToScan(packages)
				.build();
	}

}
